package com.labyrinth.core;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;

import static com.badlogic.gdx.graphics.GL10.GL_TRIANGLE_STRIP;

public class Clock extends GameInterface
{

    private int time1;
    private final int number;

    private final Vector2D position;
    public String timer;

    public Clock(float x, float y, int Number)
    {
        this.number = Number;
        this.position = new Vector2D(x, y);
        this.setScale(50, 20);
        timer = "data/time/Time0.png";
        this.texture = setTexture2(timer, this.texture);
        this.setScale(50, 20);
        setDrawType(GL_TRIANGLE_STRIP);
        setMesh();
    }

    void getTime(int clock)
    {

        switch (number)
        {
            case 1:
                this.time1 = clock % 10;
                break;
            case 2:
                this.time1 = (clock - (clock % 10)) / 10;
                break;
            case 3:
                this.time1 = (clock - clock % 100) / 100;
                break;
        }
    }

    public void setClock(int clock)
    {
        this.time1 = clock;
        this.getTime(this.time1);
        String time = "";
        switch (time1)
        {
            case 0:
                time = "data/time/Time0.png";
                break;
            case 1:
                time = "data/time/Time1.png";
                break;
            case 2:
                time = "data/time/Time2.png";
                break;
            case 3:
                time = "data/time/Time3.png";
                break;
            case 4:
                time = "data/time/Time4.png";
                break;
            case 5:
                time = "data/time/Time5.png";
                break;
            case 6:
                time = "data/time/Time6.png";
                break;
            case 7:
                time = "data/time/Time7.png";
                break;
            case 8:
                time = "data/time/Time8.png";
                break;
            case 9:
                time = "data/time/Time9.png";
                break;

        }

        this.timer = time;
    }

    @Override
    public void draw()
    {
        Gdx.gl10.glPushMatrix();
        Gdx.gl10.glTranslatef(position.getX(), position.getY(), 0);
        Gdx.gl10.glScalef(scalex, scaley, 0);
        this.texture = setTexture2(this.timer, this.texture);
        Gdx.graphics.getGL10().glEnable(GL10.GL_TEXTURE_2D);
        this.texture.bind();
        mesh.render(drawType, 0, vertexCount);
        Gdx.gl10.glPopMatrix();

    }
}
